﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Media.Imaging;

namespace STEditor.Classes.Tests
{
    [TestClass]
    public class STTileTests
    {

        private STTile _tile = null;

        [TestInitialize]
        public void Initialize()
        {
            _tile = new STTile();
        }

        [TestMethod]
        public void STTile_Should_Have_Row_And_Column()
        {

            int expectedRow = 1;
            int expectedCol = 2;

            _tile.Row = expectedRow;
            _tile.Column = expectedCol;

            Assert.AreEqual(expectedRow, _tile.Row, "Row was not set correctly");
            Assert.AreEqual(expectedCol, _tile.Column, "Column was not set correctly");

        }

        [TestMethod]
        public void STTile_Should_Have_Position_Calculated_From_Row_And_Col_And_Tile_Size()
        {

            int row = 1;
            int col = 2;

            var gameArea = new STGameArea { TileWidth = 20, TileHeight = 30, Width = 1, Height = 1 };
            _tile.Row = row;
            _tile.Column = col;
            gameArea.Tiles.Add(_tile);

            Assert.AreEqual(col * gameArea.TileWidth, _tile.X, "X was not calculated correctly");
            Assert.AreEqual(row * gameArea.TileHeight, _tile.Y, "Y was not calculated correctly");

        }

        [TestMethod]
        public void STTile_Should_Know_Which_GameArea_It_Belongs_To()
        {
            STGameArea gameArea = new STGameArea();
            gameArea.Tiles.Add(_tile);
            Assert.AreEqual(gameArea, _tile.GameArea, "GameArea was not set correctly");
        }

        [TestMethod]
        public void STTile_Should_Have_Blocking_Property_With_Default_False()
        {
            Assert.IsFalse(_tile.Blocking, "Tile.Blocking is not false per default");

            _tile.Blocking = true;
            Assert.IsTrue(_tile.Blocking, "Tile.Blocking was not set to true");

        }

        [TestMethod]
        public void STTile_Removed_From_GameArea_Should_Not_Belong_To_Any_GameArea()
        {
            STGameArea gameArea = new STGameArea();
            gameArea.Tiles.Add(_tile);
            gameArea.Tiles.Remove(_tile);
            Assert.IsNull(_tile.GameArea, "GameArea is not null");
        }

        [TestMethod]
        public void STTile_Should_Inherit_Size_From_Its_GameArea()
        {

            int expectedWidth = 10;
            int expectedHeight = 20;

            STGameArea gameArea = new STGameArea { TileWidth = expectedWidth, TileHeight = expectedHeight };
            gameArea.Tiles.Add(_tile);

            Assert.AreEqual(expectedWidth, _tile.Width, "Width is not inherited from GameArea");
            Assert.AreEqual(expectedHeight, _tile.Height, "Height is not inherited from GameArea");

        }

        [TestMethod]
        public void STTile_Should_Have_Image_Property()
        {

            var expectedImage = new STFrame();

            _tile.Image = expectedImage;

            Assert.AreSame(expectedImage, _tile.Image, "Image was not set correctly");

        }

        [TestMethod]
        public void STTile_Blocking_Should_Inherit_Value_From_Frame()
        {

            _tile.Image = new STFrame { Blocking = true };
            Assert.IsTrue(_tile.Blocking, "Blocking was not inherited from frame");

        }

        [TestMethod]
        public void STTile_Blocking_Should_Override_Inherited_Value()
        {

            _tile.Image = new STFrame { Blocking = true };
            _tile.Blocking = false;
            Assert.IsFalse(_tile.Blocking, "Blocking was not overriden by tile");

        }

    }
}
